﻿using System;
using System.Collections.Generic;
using System.Text;
using Castle.ActiveRecord;
using System.Collections;
using Castle.ActiveRecord.Queries;

namespace Mang24k99.Model.COMM
{
    [ActiveRecord("KT_COMM_BASEINFO")]
    public  class MKtCommBaseInfo:ActiveRecordBase
    {
        #region Model

        private int _id;
        private string _factor_code;
        private string _factor_name;
        private string _factor_value;
        private string _comments;
        private int? _is_validate;
        private DateTime? _input_time;
        private DateTime? _modify_time;
        private DateTime? _delete_time;
        
        /// <summary>
        /// 主键ID
        /// </summary>
        [PrimaryKey(PrimaryKeyType.Native, "ID")]
        public int ID
        {
            set { _id = value; }
            get { return _id; }
        }

        /// <summary>
        /// 参数编码
        /// </summary>
        [Property("FACTOR_CODE")]
        public string FACTOR_CODE
        {
            set { _factor_code = value; }
            get { return _factor_code; }
        }

        /// <summary>
        /// 参数名称
        /// </summary>
        [Property("FACTOR_NAME")]
        public string FACTOR_NAME
        {
            set { _factor_name = value; }
            get { return _factor_name; }
        }

        /// <summary>
        /// 参数值
        /// </summary>
        [Property("FACTOR_VALUE")]
        public string FACTOR_VALUE
        {
            set { _factor_value = value; }
            get { return _factor_value; }
        }

        /// <summary>
        /// 备注
        /// </summary>
        [Property("COMMENTS")]
        public string COMMENTS
        {
            set { _comments = value; }
            get { return _comments; }
        }

        /// <summary>
        /// 是否有效：0——使用，1——禁用
        /// </summary>
        [Property("IS_VALIDATE")]
        public int? IS_VALIDATE
        {
            set { _is_validate = value; }
            get { return _is_validate; }
        }

        /// <summary>
        /// 输入时间
        /// </summary>
        [Property("INPUT_TIME")]
        public DateTime? INPUT_TIME
        {
            set { _input_time = value; }
            get { return _input_time; }
        }

        /// <summary>
        /// 修改时间
        /// </summary>
        [Property("MODIFY_TIME")]
        public DateTime? MODIFY_TIME
        {
            set { _modify_time = value; }
            get { return _modify_time; }
        }

        /// <summary>
        /// 删除时间
        /// </summary>
        [Property("DELETE_TIME")]
        public DateTime? DELETE_TIME
        {
            set { _delete_time = value; }
            get { return _delete_time; }
        }

        #endregion Model
        #region Static Methods



        /// <summary>
        /// Selects the by primary key.
        /// </summary>
        /// <param name="ID">The ID.</param>
        /// <returns></returns>
        public static MKtCommBaseInfo SelectByPrimaryKey(object ID)
        {
            return (MKtCommBaseInfo)FindByPrimaryKey(typeof(MKtCommBaseInfo), ID, false);
        }




        protected override void OnDelete()
        {
            MKtCommBaseinfoHistory mHistory = new MKtCommBaseinfoHistory();
            Common.ModelCommon.CopyObjectValues(this, mHistory);
            mHistory.DELETE_TIME = DateTime.Now;
            mHistory.Create();
            base.OnDelete();
        }
        /// <summary>
        /// 创建一条记录
        /// </summary>
        /// <param name="commbase"></param>
        public static void Create(MKtCommBaseInfo commbase)
        {
            commbase.Create();
        }
        /// <summary>
        /// 修改一条记录
        /// </summary>
        /// <param name="commbase"></param>
        public static void Update(MKtCommBaseInfo commbase)
        {
            commbase.Update();
        }
        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="commbase"></param>
        public static void Delete(MKtCommBaseInfo commbase)
        {
            commbase.Delete();
        }
        /// <summary>
        /// 选择所有记录
        /// </summary>
        public static MKtCommBaseInfo[] SelectAll()
        {
            return (MKtCommBaseInfo[])FindAll(typeof(MKtCommBaseInfo));
        }

        /// <summary>
        /// 根据主键选择一条记录
        /// </summary>
        /// <param name="id"></param>
        public static MKtCommBaseInfo Select( int id)
        {
            return (MKtCommBaseInfo)FindByPrimaryKey(typeof(MKtCommBaseInfo), id);
        }

        /// <summary>
        /// 根据某Property列返回符合条件的记录条数
        /// </summary>
        /// <returns></returns>
        public static int SelectByProperty(string strPro,object Value)
        {
            MKtCommBaseInfo[] baseinfo;
            baseinfo=(MKtCommBaseInfo[])FindAllByProperty(typeof(MKtCommBaseInfo), strPro, Value);
            return baseinfo.Length;
        }
        /// <summary>
        /// 根据参数代码返回参数值
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetValueByCode(string code)
        {
            string hql = @"select baseinfo.FACTOR_VALUE from MKtCommBaseInfo baseinfo ";
                    hql+=@"where baseinfo.FACTOR_CODE= '"+code+"'";
            ScalarQuery query = new ScalarQuery(typeof(MKtCommBaseInfo),hql);
            return (string)ExecuteQuery(query);
        }

        public static IList<MKtCommBaseInfo> FindALLSliced(int start,int max,string where)
        {
            string hql = @"from MKtCommBaseInfo baseinfo  "+where;
            SimpleQuery query = new SimpleQuery(typeof(MKtCommBaseInfo),hql);
            query.SetQueryRange(start, max);
            return (IList<MKtCommBaseInfo>)ExecuteQuery(query);
        }
        /// <summary>
        /// 根据where条件返回符合条件记录数
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static int GetCount(string where)
        {
            string hql = @"select count(*) from MKtCommBaseInfo baseinfo "+where;
            ScalarQuery query = new ScalarQuery(typeof(MKtCommBaseInfo),hql);
            return Convert.ToInt32(ExecuteQuery(query));
        }
        #endregion Static Methods
    }
}
